package com.yc.aspect;

import com.yc.domain.MessageBean;
import com.yc.mapper.UserMapper;

import com.yc.model.UserVO;
import com.yc.service.JmsMessageProducer;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author zwei
 * @create 2024-09-24 16:12
 */
@Aspect           //切面
@Component
@Order(10)
public class UserControllerAspect {
    @Autowired
    private JmsMessageProducer jmsMessageProducer;
    @Autowired
    private UserMapper userMapper;
    //接入点表达式
    @Pointcut("execution(* com.yc.controller.UserConteoller.login(..))")
    public void login() {
    }
    @AfterReturning("login()")
    public void afterReturning(JoinPoint jp) {
        Object[] objs = jp.getArgs();
        UserVO userVO = (UserVO) objs[0];   //获取第一个参数
        String username = userVO.getUsername();   //获取用户名
        //根据用户名查找用户信息
        String optype="login";
        jmsMessageProducer.sendMessage(new MessageBean(username,0.0,optype,userVO.getEmail()));
    }
}
